package com.yueban.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.yueban.R;

import java.util.List;

/**
 * Created by guan on 17-8-7.
 */

public class ChoosePictureAdapter extends BaseAdapter {
    private LayoutInflater layoutInflater;
    private List<Bitmap> pictures;


    public ChoosePictureAdapter(Context context, List<Bitmap> pictures) {
        layoutInflater = LayoutInflater.from(context);
        this.pictures = pictures;
    }

    @Override
    public int getCount() {
        return pictures.size();
    }

    @Override
    public Object getItem(int i) {
        return pictures.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        GridViewHolder gridViewHolder;
        if (view == null) {
            view = layoutInflater.inflate(R.layout.item_release_gridview, null);
            gridViewHolder = new GridViewHolder(view);
            view.setTag(gridViewHolder);
        } else {
            gridViewHolder = (GridViewHolder) view.getTag();
        }
        gridViewHolder.imageView.setImageBitmap(pictures.get(i));
        return view;
    }

    private class GridViewHolder {
        private ImageView imageView;

        private GridViewHolder(View v) {
            imageView = (ImageView) v.findViewById(R.id.pictureChosen);
        }
    }
}
